package com.fbt.energy.controller;


import com.fbt.energy.entity.Barcode;
import com.fbt.energy.service.BarcodeService;

import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;

/**
 * 条码表(Barcode)表控制层
 *
 * @author makejava
 * @since 2021-12-12 18:23:59
 */
@CrossOrigin
@RestController
@Api(tags = {"条码表(Barcode)表控制层"})
@RequestMapping("/barcode")
public class BarcodeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private BarcodeService barcodeService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Log(title="条码表")
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("/{id}")
    public ResponseEntity<Barcode> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.barcodeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param barcode 实体
     * @return 新增结果
     */
    @Log(title="条码表",businessType= BusinessType.INSERT)
    @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<Barcode> add(Barcode barcode) {
        System.out.println(barcode.toString()+"00000000000000000000000");
        return ResponseEntity.ok(this.barcodeService.insert(barcode));
    }

    /**
     * 编辑数据
     *
     * @param barcode 实体
     * @return 编辑结果
     */

    @Log(title="条码表",businessType=BusinessType.UPDATE)
    @ApiOperation("修改数据")
    @PutMapping
    public ResponseEntity<Barcode> edit(Barcode barcode) {
        return ResponseEntity.ok(this.barcodeService.update(barcode));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Log(title="条码表",businessType=BusinessType.DELETE)
    @ApiOperation("根据主键删除数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.barcodeService.deleteById(id));
    }

}

